package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.OnshelvesMapper;
import com.zld.smarket.dto.OnshelvesList;
import com.zld.smarket.dto.StockList;
import com.zld.smarket.pojo.GoodsType;
import com.zld.smarket.pojo.Onshelves;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.OnshelvesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OnshelvesServiceImpl implements OnshelvesService {

    @Autowired
    private OnshelvesMapper onshelvesMapper;

    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<OnshelvesList> onshelvesLists = onshelvesMapper.selectAllAndPage(page,limit);
        Long count = onshelvesMapper.countOnshelves();
        return new ResponseData(onshelvesLists,count);
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<OnshelvesList> onshelvesLists =  onshelvesMapper.search(s,page,limit);
        Long count = onshelvesMapper.countOnshelves();
        return new ResponseData(onshelvesLists,count);
    }

    @Override
    public List<Onshelves> selectGoods(Long goodsNo, Long shelvesNo, Long supplierId) {
        return onshelvesMapper.selectGoods(goodsNo,shelvesNo,supplierId);
    }

    @Override
    public Integer addnum(Long id,Long shelvesonNum) {
        return onshelvesMapper.addnum(id,shelvesonNum);
    }

    @Override
    public Integer addOnshelves(Onshelves onshelve) {
        int j=0;
        j=onshelvesMapper.insert(onshelve);
        return j;
    }

    @Override
    public Integer reduceNum(Long goodsNo, Long supplierId, Long shelvesNo, Long shelvesdownNum) {
        return onshelvesMapper.reduceNum(goodsNo,supplierId,shelvesNo,shelvesdownNum);
    }
}
